//
//  GradientBtn.swift
//  todoios
//
//  Created by qianli on 2025/4/22.
//

import Foundation
import UIKit

//渐变背景的文字按钮
class GradientBtn: UIButton {
    deinit {
        QianliUniversalFunc.QianliLog("------GradientBtn.deinit")
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    init(frame:CGRect,title:String){
        super.init(frame: frame)
        self.GHL4Rhb91XYBer27(title)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func GHL4Rhb91XYBer27(_ title:String){
        self.layer.cornerRadius = self.bounds.height/2
        self.clipsToBounds = true
        self.setTitle(title, for: .normal)
        self.setTitleColor(.white, for: .normal)
        self.titleLabel?.font = .systemFont(ofSize: 15)
        let gradientLayer = CAGradientLayer()
        gradientLayer.colors = [UIColor(hexString: "#6184FF").cgColor, UIColor(hexString: "#3762FF").cgColor]
        gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0)
        gradientLayer.endPoint = CGPoint(x: 0.5, y: 1.0)
        gradientLayer.frame = self.bounds
        self.layer.insertSublayer(gradientLayer, at: 0)
    }
}
